package com.itheima.service.impl.cms;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.core.PageInfo;
import com.itheima.mapper.cms.CmsSubjectMapper;
import com.itheima.pojo.cms.CmsSubject;
import com.itheima.service.cms.CmsSubjecService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@DubboService
public class CmsSubjecServiceImpl extends ServiceImpl<CmsSubjectMapper,CmsSubject> implements CmsSubjecService{

    @Autowired
    private CmsSubjectMapper cmsSubjectMapper;

    /*获取全部商品专题*/
    @Override
    public List<CmsSubject> listAll() {


        return cmsSubjectMapper.listAll();
    }
    @Autowired
    private CmsSubjecService cmsSubjecService;

    /*根据专题名称分页获取商品专题*/
    @Override
    public PageInfo pageinfo(String keyword, Integer pageNum, Integer pageSize) {

        Page<CmsSubject> objectPage = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CmsSubject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(CmsSubject::getCategoryName,keyword);

        queryWrapper.orderByDesc(CmsSubject::getId);

        Page<CmsSubject> page = this.page(objectPage, queryWrapper);

        List<CmsSubject> records = page.getRecords();
        int total = (int)page.getTotal();
        int current = (int)page.getCurrent();


        PageInfo pageInfo = new PageInfo();
        pageInfo.setList(records);
        pageInfo.setTotal(total);
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotalPage(current);
        return pageInfo;
    }


}
